package com.ttg.controller;

//~--- non-JDK imports --------------------------------------------------------

import com.ttg.config.Properties;
import com.ttg.contants.KeyContants;
import com.ttg.data.InitGatewayReqData;
import com.ttg.pojo.TakeOverGoodsReqDTO;

import com.ttg.security.SecurityKit;
import com.ttg.utils.HttpKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

//~--- classes ----------------------------------------------------------------

/**
 * Class GwDeliveryDemoController
 * Description 说明：确认收货接口测试DEMO
 * Create 2016-08-09 13:39:05
 * @author Ardy
 */
@Controller
@RequestMapping
public class GwDeliveryDemoController {

    /**
     * Field LOGGER
     * Description
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(GwDeliveryDemoController.class);

    /**
     * Method testDeliveryDemo
     * Description 说明：确认收货接口
     *
     * @return 返回值说明：
     */
    @RequestMapping("/delivery")
    public ModelAndView testDeliveryDemo() {
        TakeOverGoodsReqDTO takeOverGoodsReq = InitGatewayReqData.initTakeOverGoodsReq();
        ModelAndView        modelAndView     = new ModelAndView();
        String              url              = "req_delivery";

        modelAndView.addObject("url", url);
        modelAndView.setViewName("demo/delivery_req_demo");
        modelAndView.addObject("delivery", takeOverGoodsReq);

        return modelAndView;
    }

    /**
     * Method reqDelivery
     * Description 说明：
     *
     * @param merchantId 说明：
     * @param merOrderId 说明：
     * @param oriMerOrderId 说明：
     * @param sellerMediId 说明：
     * @param buyerMediId 说明：
     * @param mediPwdCheck 说明：
     * @param mediPwd 说明：
     *
     * @return 返回值说明：
     */
    @RequestMapping("/req_delivery")
    public ModelAndView reqDelivery(@RequestParam(
        value    = "merchantId",
        required = true
    ) String merchantId, @RequestParam(
        value    = "merOrderId",
        required = true
    ) String merOrderId, @RequestParam(
        value    = "oriMerOrderId",
        required = true
    ) String oriMerOrderId, @RequestParam(
        value    = "sellerMediId",
        required = false
    ) String sellerMediId, @RequestParam(
        value    = "buyerMediId",
        required = false
    ) String buyerMediId, @RequestParam(
        value    = "mediPwdCheck",
        required = true
    ) Integer mediPwdCheck, @RequestParam(
        value    = "mediPwd",
        required = false
    ) String mediPwd) {
        TakeOverGoodsReqDTO takeOverGoodsReq = new TakeOverGoodsReqDTO();

        takeOverGoodsReq.setMerchantId(merchantId);
        takeOverGoodsReq.setMerOrderId(merOrderId);
        takeOverGoodsReq.setOriMerOrderId(oriMerOrderId);
        takeOverGoodsReq.setSellerMediId(sellerMediId);
        takeOverGoodsReq.setBuyerMediId(buyerMediId);
        takeOverGoodsReq.setMediPwdCheck(mediPwdCheck);
        takeOverGoodsReq.setMediPwd(mediPwd);
        takeOverGoodsReq.setSignatureAlgorithm(KeyContants.SECURITY_TYPE);
        takeOverGoodsReq.setSignatureInfo(
                SecurityKit.signByRSA(HttpKit.httpGwParam2SignStr(takeOverGoodsReq.getAllParameters())));

        ModelAndView modelAndView = new ModelAndView();
        String       url          = Properties.URL.getString("GATEWAY_BASE_SCHEME")
                                    + Properties.URL.getString("DELIVERY_URL");

        modelAndView.addObject("url", url);
        modelAndView.setViewName("req/delivery_demo");
        modelAndView.addObject("delivery", takeOverGoodsReq);

        return modelAndView;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
